package com.zero.jewelry.custom.aspect;

import com.zero.jewelry.custom.annotaion.ReMoveRedisCacheAtLast;
import lombok.RequiredArgsConstructor;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

@Component
@Aspect
@RequiredArgsConstructor
public class RemoveRedisCacheAtLastAspect {

    private final StringRedisTemplate stringRedisTemplate;

    /**
     * 方法执行完后删除缓存
     */
    @AfterReturning(value = "@annotation(anno)")
    public void boBefore(JoinPoint joinPoint, ReMoveRedisCacheAtLast anno) {
        String[] value = anno.value();
        for (String s : value) {
            stringRedisTemplate.delete(s);
        }
    }

}
